<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello React!</title>
<!-- react核心库 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script>
<!-- 支持react操作DOM -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script>
<!-- 引入Babel，用于将JSX转换为JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
<!-- prop-types -->
<script src="https://unpkg.com/prop-types@15.7.2/prop-types.js"></script>

</head>
<body>
<div id="test"></div>
<script type="text/babel"> 
    class Demo extends React.Component{

        //回调函数满足3个点
        //1.自己定义的函数
        //2.自己并没有调用
        //3.react来调用了
        showData = ()=> {
            alert(this.input1.value)
        }

        showData2 = ()=> {
            alert(this.input2.value)
        }

        //因为这个函数react会调用
        //ref是回调函数
        render(){
            return(
                <div>
                    <input ref={(currentNode)=>{this.input1 = currentNode}} type="text" placeholder="点击按钮提示数据"></input>&nbsp;
                    <button onClick={this.showData}>提交</button>&nbsp;
                    <input ref={c => this.input2 = c} onBlur={this.showData2} type="text" placeholder="失去焦点提示数据"></input>
                </div>
            )
        }
    }
    ReactDOM.render(<Demo/>,document.getElementById('test'))
</script>
</body>
</html>